package io;

/**
 *
 * @author Grega
 */
public class DisplayUtils
{
  public static void tableView(Object[][] data, int vGap, int hGap,
          int cellLength)
  {
    for (int i = 0; i < data.length; i++) {
      for (int j = 0; j < data[i].length; j++) {
        try {
          System.out.print(data[i][j].toString().substring(0, cellLength));
        } catch (IndexOutOfBoundsException ex) {
          System.out.print(data[i][j].toString());
          for (int k = 0; k < cellLength - data[i][j].toString().length(); k++) {
            System.out.print(" ");
          }
        }
        for (int k = 0; k < hGap; k++) {
          System.out.print(" ");
        }
      }
      for (int j = 0; j < vGap; j++) {
        System.out.println("");
      }
    }
  }

  public static Object[][] labelByInteger(Object[][] data)
  {
    Object[][] result = new Object[data.length + 1][];
    int max = 0;
    for (int i = 1; i < result.length; i++) {
      max = (data[i - 1].length > max ? data[i - 1].length : max);
      result[i] = new Object[data[i - 1].length + 1];

      result[i][0] = i - 1;
      for (int j = 1; j < result[i].length; j++) {
        result[i][j] = data[i - 1][j - 1];
      }
    }

    result[0] = new Object[max + 1];

    if (result[0].length > 0) {
      result[0][0] = "";
    }
    for (int j = 1; j < result[0].length; j++) {
      result[0][j] = j - 1;
    }
    return result;
  }

}
